import { Component, Input, OnInit } from '@angular/core';
import { BoardStatsVo } from 'src/app/model/board-stats-vo';
import { BoardVo } from 'src/app/model/board-vo';
import { BoardService } from 'src/app/services/board.service';

@Component({
  selector: 'app-board-item-collect-embed',
  templateUrl: './board-item-collect-embed.component.html',
  styles: [``]
})
export class BoardItemCollectEmbedComponent implements OnInit {
  @Input('boardArr')
  private boardes: BoardVo[] = [];
  private statses: BoardStatsVo[] = [];

  constructor(private boardService: BoardService) { }

  ngOnInit(): void {
    let boardIds: number[] = this.boardes.map(b => b.id);
    this.boardService.getMultiStats(boardIds).subscribe(res=>this.statses = res);
  }

  public getTodayThreads(boardId: number): number{
    let bsv: BoardStatsVo | undefined = this.statses.find(ele => ele.boardId === boardId);
    if (!bsv) {
      return 0;
    }
    return bsv.todayTopics;
  }
}
